{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 运算符"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "算术运算符：+ , - , * , / , % , ** ，//"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "9/3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "9%3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "11%3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    " 2**3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    " 2**4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "10//3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "比较运算符： == , != , > , < , >= , <="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1 == 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1 != 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "2 > 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1 > 2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "1 <= 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "逻辑运算符：and or not"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "3>1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "2>1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "3>1 and 2>1 and 2>3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "3>1 or 1>2 or 2>3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "not 2>1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "not (1>0 and 2>1 and 3>2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "path  = 'd:/123'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "not os.path.exists(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if not os.path.exists(path):\n",
    "    os.mkdir(path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 条件语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 12\n",
    "if a%2 == 0:\n",
    "    print('{}是偶数。'.format(a))\n",
    "else:\n",
    "    print('{}是奇数。'.format(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 15 \n",
    "if a%3 == 0:\n",
    "    print('MOD3余数是0。')\n",
    "elif a%3 == 1:\n",
    "    print('MOD3余数是1。')\n",
    "else:\n",
    "    print('MOD3余数是2。')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 12\n",
    "if a%3 == 0 and a > 10:\n",
    "    print('MOD3余数是0。')\n",
    "elif a%3 == 1:\n",
    "    print('MOD3余数是1。')\n",
    "elif a%3 == 2:\n",
    "    print('MOD3余数是2。')\n",
    "       "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 循环语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "li = ['a','b','c','d','e']\n",
    "print(li[0])\n",
    "print(li[1])\n",
    "print(li[2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "code_folding": []
   },
   "outputs": [],
   "source": [
    "for x in li:\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "len(li)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(0,len(li)):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(0,len(li)):\n",
    "    print(li[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "li2 = [1,2,3,4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "li3 = [] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for x in li2:\n",
    "    li3.append(x**2)\n",
    "li3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## while 循环"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "while循环能做的for循环也能做，所以while 循环了解就行了，不是重点。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "li4  = [1,2,3,4,5,6,7,8,9,10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "i = 0\n",
    "while i < 5:\n",
    "    print(li4[i])\n",
    "    i += 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "while循环最大的用处就是一些需要永远执行的任务比如每天从数据库提取报表，监控某个程序的运行状态等等，一般使用while循环,例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "while True:\n",
    "    做XXX事情\n",
    "#因为这里的True永远都不会改变，所以只要电脑不死机这件事情就会一直做下去"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 两个条件语句的例子"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 学生成绩分等级。这是一个最典型也是最简单的条件语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将学生考试成绩（score）分为5个等级（grade）：\n",
    "90-100分的为'优'；\n",
    "80-90分的为'良'；\n",
    "70-80分的为'中'；\n",
    "60-70分的为'差'；\n",
    "60分以下的为'不合格'；\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'不合格'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score = 50\n",
    "\n",
    "if score >= 90 and  score <= 100 :\n",
    "    grade = '优'\n",
    "elif score >= 80 and  score < 90 :\n",
    "    grade = '良'\n",
    "elif score >= 70 and  score < 80 :\n",
    "    grade = '中'\n",
    "elif score >= 60 and  score < 70 :\n",
    "    grade = '差'\n",
    "else:\n",
    "    grade = '不合格'\n",
    "    \n",
    "grade"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 吃早点 。这个例子非常复杂，请自己尝试修改条件多实操几遍，深刻领会。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有一个人，他早点习惯吃油条。如果早点铺有油条他就选油条，最好是搭配豆浆；没有豆浆的话稀豆粉也可以；没有稀豆粉，稀饭也可以；没有稀饭的话，他就不吃油条，因为太干了吃不下；他就改吃米线或面条。如果早点铺没有油条，他就吃米线；如果没有米线，他就吃面条，如果连面条都没有他就不吃早点。\n",
    "早点铺1-5卖的早点各不相同，用一个条件语句判断他会吃什么早点。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['油条', '豆浆']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zao_dian_pu1 = ['油条','豆浆','稀豆粉','稀饭','米线','面条'] \n",
    "my_zaodian = []\n",
    "\n",
    "if '油条' in zao_dian_pu1:\n",
    "    my_zaodian.append('油条')\n",
    "    if '豆浆' in zao_dian_pu1:\n",
    "        my_zaodian.append('豆浆')\n",
    "    elif '稀豆粉' in zao_dian_pu1:\n",
    "        my_zaodian.append('稀豆粉')\n",
    "    elif '稀饭' in zao_dian_pu1:\n",
    "        my_zaodian.append('稀饭')\n",
    "    else:\n",
    "        my_zaodian.remove('油条')\n",
    "        if '米线' in zao_dian_pu1:\n",
    "            my_zaodian.append('米线')\n",
    "        elif '面条' in zao_dian_pu1:\n",
    "            my_zaodian.append('面条') \n",
    "        else:\n",
    "            pass\n",
    "elif '米线' in zao_dian_pu1:\n",
    "    my_zaodian.append('米线')\n",
    "elif '面条' in zao_dian_pu1:\n",
    "    my_zaodian.append('面条')\n",
    "else:\n",
    "    pass\n",
    "\n",
    "my_zaodian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "code_folding": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['油条', '稀饭']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zao_dian_pu2 = ['油条','稀饭','米线','面条'] \n",
    "my_zaodian = []\n",
    "\n",
    "if '油条' in zao_dian_pu2:\n",
    "    my_zaodian.append('油条')\n",
    "    if '豆浆' in zao_dian_pu2:\n",
    "        my_zaodian.append('豆浆')\n",
    "    elif '稀豆粉' in zao_dian_pu2:\n",
    "        my_zaodian.append('稀豆粉')\n",
    "    elif '稀饭' in zao_dian_pu2:\n",
    "        my_zaodian.append('稀饭')\n",
    "    else:\n",
    "        my_zaodian.remove('油条')\n",
    "        if '米线' in zao_dian_pu2:\n",
    "            my_zaodian.append('米线')\n",
    "        elif '面条' in zao_dian_pu2:\n",
    "            my_zaodian.append('面条') \n",
    "        else:\n",
    "            pass\n",
    "elif '米线' in zao_dian_pu2:\n",
    "    my_zaodian.append('米线')\n",
    "elif '面条' in zao_dian_pu2:\n",
    "    my_zaodian.append('面条')\n",
    "else:\n",
    "    pass\n",
    "\n",
    "my_zaodian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "code_folding": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zao_dian_pu3 = ['油条','包子','馒头'] \n",
    "my_zaodian = []\n",
    "\n",
    "if '油条' in zao_dian_pu3:\n",
    "    my_zaodian.append('油条')\n",
    "    if '豆浆' in zao_dian_pu3:\n",
    "        my_zaodian.append('豆浆')\n",
    "    elif '稀豆粉' in zao_dian_pu3:\n",
    "        my_zaodian.append('稀豆粉')\n",
    "    elif '稀饭' in zao_dian_pu3:\n",
    "        my_zaodian.append('稀饭')\n",
    "    else:\n",
    "        my_zaodian.remove('油条')\n",
    "        if '米线' in zao_dian_pu3:\n",
    "            my_zaodian.append('米线')\n",
    "        elif '面条' in zao_dian_pu3:\n",
    "            my_zaodian.append('面条') \n",
    "        else:\n",
    "            pass\n",
    "elif '米线' in zao_dian_pu3:\n",
    "    my_zaodian.append('米线')\n",
    "elif '面条' in zao_dian_pu3:\n",
    "    my_zaodian.append('面条')\n",
    "else:\n",
    "    pass\n",
    "\n",
    "my_zaodian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['米线']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zao_dian_pu4 = ['油条','米线','面条'] \n",
    "my_zaodian = []\n",
    "\n",
    "if '油条' in zao_dian_pu4:\n",
    "    my_zaodian.append('油条')\n",
    "    if '豆浆' in zao_dian_pu4:\n",
    "        my_zaodian.append('豆浆')\n",
    "    elif '稀豆粉' in zao_dian_pu4:\n",
    "        my_zaodian.append('稀豆粉')\n",
    "    elif '稀饭' in zao_dian_pu4:\n",
    "        my_zaodian.append('稀饭')\n",
    "    else:\n",
    "        my_zaodian.remove('油条')\n",
    "        if '米线' in zao_dian_pu4:\n",
    "            my_zaodian.append('米线')\n",
    "        elif '面条' in zao_dian_pu4:\n",
    "            my_zaodian.append('面条') \n",
    "        else:\n",
    "            pass\n",
    "elif '米线' in zao_dian_pu4:\n",
    "    my_zaodian.append('米线')\n",
    "elif '面条' in zao_dian_pu4:\n",
    "    my_zaodian.append('面条')\n",
    "else:\n",
    "    pass\n",
    "\n",
    "my_zaodian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "code_folding": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['面条']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zao_dian_pu5 = ['油条','面条'] \n",
    "my_zaodian = []\n",
    "\n",
    "if '油条' in zao_dian_pu5:\n",
    "    my_zaodian.append('油条')\n",
    "    if '豆浆' in zao_dian_pu5:\n",
    "        my_zaodian.append('豆浆')\n",
    "    elif '稀豆粉' in zao_dian_pu5:\n",
    "        my_zaodian.append('稀豆粉')\n",
    "    elif '稀饭' in zao_dian_pu5:\n",
    "        my_zaodian.append('稀饭')\n",
    "    else:\n",
    "        my_zaodian.remove('油条')\n",
    "        if '米线' in zao_dian_pu5:\n",
    "            my_zaodian.append('米线')\n",
    "        elif '面条' in zao_dian_pu5:\n",
    "            my_zaodian.append('面条') \n",
    "        else:\n",
    "            pass\n",
    "elif '米线' in zao_dian_pu5:\n",
    "    my_zaodian.append('米线')\n",
    "elif '面条' in zao_dian_pu5:\n",
    "    my_zaodian.append('面条')\n",
    "else:\n",
    "    pass\n",
    "\n",
    "my_zaodian"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 一个循环语句的例子,循环很好理解，但是循环往往会和条件语句一起使用，本例就是循环加语句条件语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "你是一个上班族，如果是星期1-5你早上7:00起床上班，下午5:30下班，晚上10:00睡觉。\n",
    "如果是星期6和星期7，你睡懒觉到12:00才起床，从13:00开始打游戏,到晚上12:00才睡觉。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==========\n",
      "今天是星期1\n",
      "早上7:00起床上班。\n",
      "下午5:30下班。\n",
      "晚上10:00睡觉。\n",
      "==========\n",
      "今天是星期2\n",
      "早上7:00起床上班。\n",
      "下午5:30下班。\n",
      "晚上10:00睡觉。\n",
      "==========\n",
      "今天是星期3\n",
      "早上7:00起床上班。\n",
      "下午5:30下班。\n",
      "晚上10:00睡觉。\n",
      "==========\n",
      "今天是星期4\n",
      "早上7:00起床上班。\n",
      "下午5:30下班。\n",
      "晚上10:00睡觉。\n",
      "==========\n",
      "今天是星期5\n",
      "早上7:00起床上班。\n",
      "下午5:30下班。\n",
      "晚上10:00睡觉。\n",
      "##########\n",
      "今天是星期6\n",
      "中午12:00起床。\n",
      "从13:00开始打游戏。\n",
      "晚上12:00睡觉。\n",
      "##########\n",
      "今天是星期7\n",
      "中午12:00起床。\n",
      "从13:00开始打游戏。\n",
      "晚上12:00睡觉。\n"
     ]
    }
   ],
   "source": [
    "day_list = [1,2,3,4,5,6,7]\n",
    "for day in day_list:\n",
    "    if day<=5:\n",
    "        print('='*10)\n",
    "        print('今天是星期{}'.format(day))\n",
    "        print('早上7:00起床上班。')\n",
    "        print('下午5:30下班。')\n",
    "        print('晚上10:00睡觉。')\n",
    "    elif day == 6 or day == 7 :\n",
    "        print('#'*10)\n",
    "        print('今天是星期{}'.format(day))\n",
    "        print('中午12:00起床。')\n",
    "        print('从13:00开始打游戏。')\n",
    "        print('晚上12:00睡觉。')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'python'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 'pyth'\n",
    "b= 'on'\n",
    "a += b\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=3\n",
    "b=4\n",
    "a +=b\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['2019_07_22_16_48_37_531_yn_zxgs_中兴忙时话务_19625.csv',\n",
       " '3GCI数据库制作',\n",
       " '修改Excel表格样式',\n",
       " '填写作业计划',\n",
       " '存量3G用户数提取',\n",
       " '曲靖BSS2_CM_载频无线参数表(DO).xls',\n",
       " '曲靖BSS2_CM_载频无线参数表(DO)1.xls',\n",
       " '曲靖手机型号库.csv',\n",
       " '福彩用户分析',\n",
       " '读写word文档']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path = 'D:/Test'\n",
    "os.listdir(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "273.188px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
